﻿using ST.Data;

namespace ST.Receiver.Tasks
{
    public class ReqAndRevVM
    {
        public int Result { get; set; }//0 正常  BreakToken  1  EndToken 2  超时3

        public UInt16 SeqNo { get; set; }
        public byte HostId { get; set; }
        public byte Gnm { get; set; }
        public bool BitData { get; set; }   
        public UInt16 StartAddress { get; set; }
        public UInt16 ReqLen { get; set; }//请求的byte数或者bit数


       

        public int PlanRevByteCount { get; set; }//返回的有效数据长度
        public byte[] SendData { get; set; }
        public byte[] RevData{ get; set; }

        public string SendMemo = "";
        public Data.ProtocolSimLog SendLog { get; set; }
        public Data.ProtocolSimLog ReceiveLog { get; set; }    
        public byte[] GetSendData()
        {
            var len = 0;
            if (BitData)
            {
                len = Convert.ToUInt16(Math.Floor(ReqLen / 8.0));
                PlanRevByteCount = len;
                len = ReqLen;
            }
            else
            {
                len = Convert.ToUInt16(Math.Floor(ReqLen / 2.0));
                PlanRevByteCount = 2 * len;
            }
            var data = new byte[6];
            data[0] = HostId;
            data[1] = Gnm;
            data[2] = Convert.ToByte(StartAddress >> 8);
            data[3] = Convert.ToByte(StartAddress & 0xff);
            data[4] = Convert.ToByte(len >> 8);
            data[5] = Convert.ToByte(len & 0xff);
            SendData = data;
            return data;
        }

    }
}
